package com.xwj.back.controller;

import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.xwj.back.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class RoleMenuController {

    @Autowired
    private RoleMenuService roleMenuService;

    @PostMapping("/roleMenu/update/")
    public Map<String,String> updateRoleMenu(@RequestBody Map<String,String> data){
        String role = data.get("role");
        Integer roleId = Integer.parseInt(data.get("roleId"));
        //没有子节点的节点集合
        List<Integer> menuIds = JSONObject.parseObject(data.get("tree"),new TypeReference<List<Integer>>(){});
        //有子节点的节点集合
        List<Integer> half = JSONObject.parseObject(data.get("half"),new TypeReference<List<Integer>>(){});
        return roleMenuService.updateRoleMenu(role,roleId,menuIds,half);
    }
}
